
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>命名路由 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="named-views.html" />
    
    
    <link rel="prev" href="navigation.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../installation.html">
            
                <a href="../installation.html">
            
                    
                    安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    基础
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="getting-started.html">
            
                <a href="getting-started.html">
            
                    
                    开始
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="dynamic-matching.html">
            
                <a href="dynamic-matching.html">
            
                    
                    动态路由匹配
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="nested-routes.html">
            
                <a href="nested-routes.html">
            
                    
                    嵌套路由
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="navigation.html">
            
                <a href="navigation.html">
            
                    
                    编程式导航
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.5" data-path="named-routes.html">
            
                <a href="named-routes.html">
            
                    
                    命名路由
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="named-views.html">
            
                <a href="named-views.html">
            
                    
                    命名视图
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="redirect-and-alias.html">
            
                <a href="redirect-and-alias.html">
            
                    
                    重定向 和 别名
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="history-mode.html">
            
                <a href="history-mode.html">
            
                    
                    HTML5 History 模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    进阶
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../advanced/navigation-guards.html">
            
                <a href="../advanced/navigation-guards.html">
            
                    
                    导航钩子
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../advanced/meta.html">
            
                <a href="../advanced/meta.html">
            
                    
                    路由元信息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../advanced/transitions.html">
            
                <a href="../advanced/transitions.html">
            
                    
                    过渡动效
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../advanced/data-fetching.html">
            
                <a href="../advanced/data-fetching.html">
            
                    
                    数据获取
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../advanced/scroll-behavior.html">
            
                <a href="../advanced/scroll-behavior.html">
            
                    
                    滚动行为
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../advanced/lazy-loading.html">
            
                <a href="../advanced/lazy-loading.html">
            
                    
                    懒加载
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    API 文档
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../api/router-link.html">
            
                <a href="../api/router-link.html">
            
                    
                    router-link
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../api/router-view.html">
            
                <a href="../api/router-view.html">
            
                    
                    router-view
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../api/route-object.html">
            
                <a href="../api/route-object.html">
            
                    
                    路由信息对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../api/options.html">
            
                <a href="../api/options.html">
            
                    
                    Router 构造配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../api/router-instance.html">
            
                <a href="../api/router-instance.html">
            
                    
                    Router 实例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="../api/component-injections.html">
            
                <a href="../api/component-injections.html">
            
                    
                    对组件注入
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >命名路由</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x547D;&#x540D;&#x8DEF;&#x7531;">&#x547D;&#x540D;&#x8DEF;&#x7531;</h1>
<p>&#x6709;&#x65F6;&#x5019;&#xFF0C;&#x901A;&#x8FC7;&#x4E00;&#x4E2A;&#x540D;&#x79F0;&#x6765;&#x6807;&#x8BC6;&#x4E00;&#x4E2A;&#x8DEF;&#x7531;&#x663E;&#x5F97;&#x66F4;&#x65B9;&#x4FBF;&#x4E00;&#x4E9B;&#xFF0C;&#x7279;&#x522B;&#x662F;&#x5728;&#x94FE;&#x63A5;&#x4E00;&#x4E2A;&#x8DEF;&#x7531;&#xFF0C;&#x6216;&#x8005;&#x662F;&#x6267;&#x884C;&#x4E00;&#x4E9B;&#x8DF3;&#x8F6C;&#x7684;&#x65F6;&#x5019;&#x3002;&#x4F60;&#x53EF;&#x4EE5;&#x5728;&#x521B;&#x5EFA; Router &#x5B9E;&#x4F8B;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5728; <code>routes</code> &#x914D;&#x7F6E;&#x4E2D;&#x7ED9;&#x67D0;&#x4E2A;&#x8DEF;&#x7531;&#x8BBE;&#x7F6E;&#x540D;&#x79F0;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> router = <span class="hljs-keyword">new</span> VueRouter({
  routes: [
    {
      path: <span class="hljs-string">&apos;/user/:userId&apos;</span>,
      name: <span class="hljs-string">&apos;user&apos;</span>,
      component: User
    }
  ]
})
</code></pre>
<p>&#x8981;&#x94FE;&#x63A5;&#x5230;&#x4E00;&#x4E2A;&#x547D;&#x540D;&#x8DEF;&#x7531;&#xFF0C;&#x53EF;&#x4EE5;&#x7ED9; <code>router-link</code> &#x7684; <code>to</code> &#x5C5E;&#x6027;&#x4F20;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF1A;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">router-link</span> <span class="hljs-attr">:to</span>=<span class="hljs-string">&quot;{ name: &apos;user&apos;, params: { userId: 123 }}&quot;</span>&gt;</span>User<span class="hljs-tag">&lt;/<span class="hljs-name">router-link</span>&gt;</span>
</code></pre>
<p>&#x8FD9;&#x8DDF;&#x4EE3;&#x7801;&#x8C03;&#x7528; <code>router.push()</code> &#x662F;&#x4E00;&#x56DE;&#x4E8B;&#xFF1A;</p>
<pre><code class="lang-js">router.push({ name: <span class="hljs-string">&apos;user&apos;</span>, params: { userId: <span class="hljs-number">123</span> }})
</code></pre>
<p>&#x8FD9;&#x4E24;&#x79CD;&#x65B9;&#x5F0F;&#x90FD;&#x4F1A;&#x628A;&#x8DEF;&#x7531;&#x5BFC;&#x822A;&#x5230; <code>/user/123</code> &#x8DEF;&#x5F84;&#x3002;</p>
<p>&#x5B8C;&#x6574;&#x7684;&#x4F8B;&#x5B50;&#x8BF7; <a href="https://github.com/vuejs/vue-router/blob/next/examples/named-routes/app.js" target="_blank">&#x6233;&#x8FD9;&#x91CC;</a>.</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="navigation.html" class="navigation navigation-prev " aria-label="Previous page: 编程式导航">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="named-views.html" class="navigation navigation-next " aria-label="Next page: 命名视图">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"命名路由","level":"1.3.5","depth":2,"next":{"title":"命名视图","level":"1.3.6","depth":2,"path":"essentials/named-views.md","ref":"essentials/named-views.md","articles":[]},"previous":{"title":"编程式导航","level":"1.3.4","depth":2,"path":"essentials/navigation.md","ref":"essentials/navigation.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"essentials/named-routes.md","mtime":"2017-03-04T12:16:27.894Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-03-06T16:00:44.406Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

